#include <iostream>
#include <cstring>
#include "Sock.hpp"

int main()
{
    Sock sock;
    sock.Socket();
    sock.Connect("127.0.0.1", 8889);
    int fd = sock.GetFd();
    while(true)
    {
        std::cout << "Enter# ";
        fflush(stdout);
        std::string sendStr;
        std::cin >> sendStr;
        int n = send(fd, sendStr.c_str(), sendStr.size(), 0);
        if(n < 0)
        {
            std::cout << "send fail, errStr: " << strerror(errno) << " , fd: " << fd << std::endl;
        }
        char buffer[1024];
        n = recv(fd, buffer, 1024, 0);
        // std::cout << "Get from server: " << buffer << std::endl;
        if(n > 0)
        {
            buffer[n] = 0;
            std::cout << "Get from server: " << buffer << std::endl;
        }
    }
    return 0;
}